I have some code which works fine on its own but when called by #include does not work. From browsing the forum I believe I need to "forward declare" some variables but am stuck and hope someone can help.
//FILE 1
DBE xVALSel = null
void doSelect(DBE xVALOpt)
{
//DBE xVALSel = null
string xVAL = get xVALOpt
set (xVALSel, xVAL)
}
string guessAndAsk ()
{
string xVALChoice[] = {"A", "B", "C", "D"}
DB xVALDB = null
DBE xVALOpt = null
//DBE xVALSel = null
DBE applyBtn = null
xVALDB = create("", styleCentered|styleFloating)
xVALOpt = list (xVALDB, "", 100, 5, xVALChoice)
xVALSel = field (xVALDB, "Specific Value: ", "" ,4)
realize xVALDB
set (xVALOpt, doSelect)
block xVALDB
return get xVALSel
}
//FILE 2
//#include <FILE 1>
guessAndAsk ()
Martin_Hunter - Tue Dec 07 11:33:07 EST 2010 |
Re: Forward Declare #include
Since callback functions routinely deal with DBEs, you should routinely declare your DB and DBE variables globally, unless your box is very simple and doesn't require anything tricky. Also, forgive ignorance but I suspect there may be an issue with declaring your xValChoice[] vector inside the function, as its de-allocated when the function ends. I'd declare that globally as well.
DB xVALDB = null
DBE xVALOpt = null
DBE xVALSel = null
DBE applyBtn = null
string xVALChoice[] = {"A", "B", "C", "D"}
void doSelect(DBE xVALOpt)
{
string xVAL = get xVALOpt
set (xVALSel, xVAL)
}
string guessAndAsk ()
{
xVALDB = create("", styleCentered|styleFloating)
xVALOpt = list (xVALDB, "", 100, 5, xVALChoice)
xVALSel = field (xVALDB, "Specific Value: ", "" ,4)
realize xVALDB
set (xVALOpt, doSelect)
block xVALDB
string RetValue = get xVALSel
hide(xVALDB)
destroy(xVALDB)
xVALDB = null
return RetValue
}
|
Re: Forward Declare #include llandale - Tue Dec 07 11:53:10 EST 2010
Since callback functions routinely deal with DBEs, you should routinely declare your DB and DBE variables globally, unless your box is very simple and doesn't require anything tricky. Also, forgive ignorance but I suspect there may be an issue with declaring your xValChoice[] vector inside the function, as its de-allocated when the function ends. I'd declare that globally as well.
DB xVALDB = null
DBE xVALOpt = null
DBE xVALSel = null
DBE applyBtn = null
string xVALChoice[] = {"A", "B", "C", "D"}
void doSelect(DBE xVALOpt)
{
string xVAL = get xVALOpt
set (xVALSel, xVAL)
}
string guessAndAsk ()
{
xVALDB = create("", styleCentered|styleFloating)
xVALOpt = list (xVALDB, "", 100, 5, xVALChoice)
xVALSel = field (xVALDB, "Specific Value: ", "" ,4)
realize xVALDB
set (xVALOpt, doSelect)
block xVALDB
string RetValue = get xVALSel
hide(xVALDB)
destroy(xVALDB)
xVALDB = null
return RetValue
}
Louie,
bool doCloseTrig (Trigger t)
{
DB xVALDB = null
DBE xVALOpt = null
DBE xVALSel = null
DBE applyBtn = null
string xVALChoice[] = {"A", "B", "C", "D"}
#include <FILE 1>
}
|
Re: Forward Declare #include Martin_Hunter - Tue Dec 07 12:33:34 EST 2010
Louie,
bool doCloseTrig (Trigger t)
{
DB xVALDB = null
DBE xVALOpt = null
DBE xVALSel = null
DBE applyBtn = null
string xVALChoice[] = {"A", "B", "C", "D"}
#include <FILE 1>
}
What you wrote here won't work since the code included in 'File 1' won't be able to access your variables e.g. xVALDB since they are not defined globally, they are in the function.
#include <FILE 1>
bool doCloseTrig (Trigger t)
{ guessAndAsk()
}
DB xVALDB = null
DBE xVALOpt = null
DBE xVALSel = null
DBE applyBtn = null
string xVALChoice[] = {"A", "B", "C", "D"}
void doSelect(DBE xVALOpt)
{
string xVAL = get xVALOpt
set (xVALSel, xVAL)
}
string guessAndAsk ()
{
xVALDB = create("", styleCentered|styleFloating)
xVALOpt = list (xVALDB, "", 100, 5, xVALChoice)
xVALSel = field (xVALDB, "Specific Value: ", "" ,4)
realize xVALDB
set (xVALOpt, doSelect)
block xVALDB
return get xVALSel
}
|